package pl.edu.agh.winmon.hibernate;

import java.io.Serializable;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.OrderColumn;
import javax.persistence.Table;
import javax.persistence.Transient;

/**
 * Represents session of collecting data.
 */
@Entity
@Table(name = "`" + Session.TABLE_NAME + "`")
public class Session implements Serializable {

	@Transient
	private static final long serialVersionUID = 2827668574229025045L;

	/**
	 * Table name.
	 */
	@Transient
	public static final String TABLE_NAME = "session"; //$NON-NLS-1$

	/**
	 * Hibernate's annotation property: id.
	 */
	@Transient
	public static final String PROP_ID = "id"; //$NON-NLS-1$

	/**
	 * Database column name: id;
	 */
	@Transient
	public static final String DB_ID = PROP_ID;

	/**
	 * Hibernate's annotation property: start time.
	 */
	@Transient
	public static final String PROP_START_TIME = "startTime"; //$NON-NLS-1$

	/**
	 * Database column name: start time;
	 */
	@Transient
	public static final String DB_START_TIME = "start_time"; //$NON-NLS-1$

	/**
	 * Hibernate's annotation property: start time.
	 */
	@Transient
	public static final String PROP_CPU_INFO = "cpuInfo"; //$NON-NLS-1$

	/**
	 * Database column name: start time;
	 */
	@Transient
	public static final String DB_CPU_INFO = "cpu_info_id"; //$NON-NLS-1$

	/**
	 * Hibernate's annotation property: session's turns.
	 */
	@Transient
	public static final String PROP_TURNS = "turns"; //$NON-NLS-1$

	/**
	 * Hibernate's annotation property: session's programs.
	 */
	@Transient
	public static final String PROP_PROGRAMS = "programs"; //$NON-NLS-1$

	@Transient
	public static final String PROP_MEMORY_INFO = "memoryInfo"; //$NON-NLS-1$

	@Transient
	public static final String DB_MEMORY_INFO = "memory_info_id"; //$NON-NLS-1$

	/**
	 * Id of the session.
	 */
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name = DB_ID)
	private Long id;

	/**
	 * Time when this session has been started.
	 */
	@Column(name = DB_START_TIME)
	private Long startTime;

	/**
	 * Information about computer's CPU.
	 */
	@OneToOne(targetEntity = CpuInfo.class)
	@JoinColumn(name = DB_CPU_INFO)
	private CpuInfo cpuInfo;

	/**
	 * Session's turns.
	 */
	@OneToMany(mappedBy = TABLE_NAME)
	@OrderColumn(name = Turn.PROP_ID)
	private List<Turn> turns;

	/**
	 * Session's programs.
	 */
	@OneToMany(mappedBy = TABLE_NAME)
	@OrderColumn(name = Program.PROP_ID)
	private List<Program> programs;

	@OneToOne(targetEntity = MemoryInfo.class)
	@JoinColumn(name = DB_MEMORY_INFO)
	private MemoryInfo memoryInfo;

	/**
	 * Returns id of the session.
	 * 
	 * @return Id of the session.
	 */
	public Long getId() {
		return id;
	}

	/**
	 * Sets id of the session.
	 * 
	 * @param id
	 *            Id of the session,
	 */
	public void setId(Long id) {
		this.id = id;
	}

	/**
	 * Returns time (in long format) when session has been started.
	 * 
	 * @return Time (in long format) when session has been started.
	 */
	public Long getStartTime() {
		return startTime;
	}

	/**
	 * Sets time (in long format) when session has been started.
	 * 
	 * @param startTime
	 *            Time (in long format) when session has been started.
	 */
	public void setStartTime(Long startTime) {
		this.startTime = startTime;
	}

	/**
	 * Returns information about computer's CPU.
	 * 
	 * @return Information about computer's CPU.
	 */
	public CpuInfo getCpuInfo() {
		return cpuInfo;
	}

	/**
	 * Sets information about computer's CPU.
	 * 
	 * @param cpuInfo
	 *            Information about computer's CPU.
	 */
	public void setCpuInfo(CpuInfo cpuInfo) {
		this.cpuInfo = cpuInfo;
	}

	/**
	 * Returns session's turns.
	 * 
	 * @return Session's turns.
	 */
	public List<Turn> getTurns() {
		return turns;
	}

	/**
	 * Sets session's turns.
	 * 
	 * @param turns
	 *            session's turns.
	 */
	public void setTurns(List<Turn> turns) {
		this.turns = turns;
	}

	/**
	 * Returns session's programs.
	 * 
	 * @return Session's programs.
	 */
	public List<Program> getPrograms() {
		return programs;
	}

	/**
	 * Sets session's programs.
	 * 
	 * @param programs
	 *            Session's programs.
	 */
	public void setPrograms(List<Program> programs) {
		this.programs = programs;
	}

	public MemoryInfo getMemoryInfo() {
		return memoryInfo;
	}

	public void setMemoryInfo(MemoryInfo memoryInfo) {
		this.memoryInfo = memoryInfo;
	}

}
